package com.demo.sso.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.stp.StpUtil;
import cn.dev33.satoken.util.SaResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/test")
public class TestController {

    /**
     * 无需登录即可访问
     */
    @RequestMapping("/notLogin")
    public SaResult notLogin() {
        return SaResult.ok("无需登录接口访问成功");
    }

    /**
     * 必须登录才能访问
     */
    @SaCheckLogin
    @RequestMapping("/needLogin")
    public SaResult needLogin() {
        return SaResult.ok("登录后接口访问成功")
                .set("username", StpUtil.getLoginIdAsString());
    }
}